package com.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Author Miracle GuGuaGuGua
 * @Date 2022/3/31 9:07
 * @Version 1.0
 */
@Data
@AllArgsConstructor
public class CommonResult<T> {
    private String code;
    private String msg;
    private T data;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public CommonResult() {
    }

    public CommonResult(T data) {
        this.data = data;
    }

    public static CommonResult success() {
        CommonResult result = new CommonResult();
        result.setCode("0");
        result.setMsg("成功");
        return result;
    }

    public static <T> CommonResult<T> success(T data) {
        CommonResult<T> result = new CommonResult(data);
        result.setCode("0");
        result.setMsg("成功");
        return result;
    }

    public static CommonResult error(String code, String msg) {
        CommonResult result = new CommonResult();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
}